﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;

namespace WindowsFormsApplication3
{
    using Reports.JobDetailsTableAdapters;
    using Reports;
    
    public partial class TotalJobCodeForm : Form
    {
        
        public TotalJobCodeForm()
        {
            InitializeComponent();
            selectaalljobcodedetail();
            comboboxload();
        }


        public void selectaalljobcodedetail()
        {

            //String query = "Select jobcodemastertable.jobcode, jobcodemastertable.companyName, jobcodemastertable.totaltrip, jobcodemastertable.shipmentdate, jobcodemastertable.fromPlace, jobcodemastertable.destination, jobcodemastertable.description, jobcodemastertable.noofpackage, jobcodemastertable.packagetype,jobcodemastertable.contactperson, confirmquotationmastertable.quotationcode , confirmquotationmastertable.amount , confirmquotationmastertable.agrdamount from jobcodemastertable ,confirmquotationmastertable where confirmquotationmastertable.jobpk=jobcodemastertable.jobpk";
            //OleDbDataAdapter dAdapter = new OleDbDataAdapter(query, connString);
            //DataSet ds = new DataSet();
            //dAdapter.Fill(ds, "tbluserdataview");
            //tbljobedata.DataSource = ds.Tables["tbluserdataview"].DefaultView;
            JobCodeTableAdapter adapt = new JobCodeTableAdapter();
            adapt.Connection = new OleDbConnection(Program.ConnStr);//This is not mandatory.just to confirm.
            DataTable dt = adapt.GetData();
            tbljobedata.DataSource = dt;

        }

        public void comboboxload()
        {

            JobCodeTableAdapter adapt = new JobCodeTableAdapter();
            adapt.Connection = new OleDbConnection(Program.ConnStr);//This is not mandatory.just to confirm.
            DataTable dt= adapt.GetJobCodes();
            cmbJobcode.ValueMember = "jobpk";
            cmbJobcode.DisplayMember = "jobcode";
            cmbJobcode.DataSource = dt;
        }


        public void selectedjobcodedetails()
        {

           
            JobCodeTableAdapter adapt = new JobCodeTableAdapter();
            adapt.Connection = new OleDbConnection(Program.ConnStr);//This is not mandatory.just to confirm.
            JobDetails.TblJobCodeDataTable dt = adapt.GetDataByjobcode(cmbJobcode.Text); // you can use datatable as class , but will not get all proprty
            tbljobedata.DataSource = dt  ;
            Utils.UpdaateMappingColumnName(tbljobedata);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            selectedjobcodedetails();
        }

        private void button2_Click(object sender, EventArgs e)
        {

        }

        private void TotalJobCodeForm_Load(object sender, EventArgs e)
        {

          //  this.reportViewer1.RefreshReport();
        }

        private void button3_Click(object sender, EventArgs e)
        {

            //A new table is created to copy data
            JobDetails.TblJobCodeDataTable details1 = new JobDetails.TblJobCodeDataTable();
            foreach(DataGridViewRow gridrow in tbljobedata.SelectedRows)
            {
                 DataRow drow = details1.NewRow();
                 drow = ((DataRowView)gridrow.DataBoundItem).Row;//get DataRow form grid view row
                 details1.ImportRow(drow);//copy to our table.
            }
            
            //JobCodeTableAdapter adapt = new JobCodeTableAdapter();
            //adapt.Connection = new OleDbConnection(Program.ConnStr);
            //JobDetails.TblJobCodeDataTable details1 = new JobDetails.TblJobCodeDataTable();
            //adapt.Fill(details1);
            RptJobCode report = new RptJobCode();
            report.SetDataSource((DataTable)details1);
            JobCodeReport frmreport = new JobCodeReport();
            frmreport.ReportSource = report;
            frmreport.ShowDialog();

        }
       


    }
}
